package com.ruoyi;

import com.alibaba.druid.filter.config.ConfigTools;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;


public class Test {

    public static void main(String[] args) throws Exception {
       // t1();
        t2();
    }

    private static void t2() throws Exception {
        String str = "Safe@2023";
        String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAozCwuQ+6cS+QSOXoqlJKOwekWvaekkrqSOyeF4fviSHPCDQIjw12dj5AdEZkdo3ygMR70sjAQPmpm3XZm1hpWwIDAQABAkAkB+4dDjH2J7BNyCV05bJqEifhxa4BUvUjoMrPGz5yIl/v2cdN26jT3GUVWW99ud2dXg6is139sPtNhjsAvM+xAiEA5pAr27uKH4wsGv51WgZQPo91LvFuAv3mkVB+L18wvY0CIQC1MbHIjkAZP9GpKY5K4wBS+Ek/6p/5AY/7MtgX8TdEhwIgHtJdGpW6hDcf2kfz9iHr7kENQEZEF6BLh1eEVt7ZzC0CIH/kbaozzcaEp0YRkOAGzgnCOmGlB/lIQwp5XtG3bt0tAiEAwOTisofVGbXzht26zedwCV7X2sFoqoh1lJlQK0nUxy0=";
        String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKMwsLkPunEvkEjl6KpSSjsHpFr2npJK6kjsnheH74khzwg0CI8NdnY+QHRGZHaN8oDEe9LIwED5qZt12ZtYaVsCAwEAAQ==";

        String encryptPassword = ConfigTools.encrypt(privateKey, str);
        String decryptPassword = ConfigTools.decrypt(publicKey, encryptPassword);
        System.out.println("加密后：" + encryptPassword);
        System.out.println("加密后：" + decryptPassword);
    }

    private static void t1() throws Exception {
        String password1 = "123456";
        String password2 = "f2kyZmNWX4_27T!5X";

        String [] keyPair = ConfigTools.genKeyPair(512);

        String privateKey = keyPair[0];
        String publicKey = keyPair[1];

        System.out.println("明文1：" + password1);
        System.out.println("明文2：" + password2);
        System.out.println("privateKey（私钥）:" + privateKey);
        System.out.println("publicKey（公钥）:" + publicKey);

        String encryptPassword = ConfigTools.encrypt(privateKey, password1);
        String decryptPassword = ConfigTools.decrypt(publicKey, encryptPassword);


        String encryptPassword2 = ConfigTools.encrypt(privateKey, password2);
        String decryptPassword2 = ConfigTools.decrypt(publicKey, encryptPassword2);

        System.out.println("加密后1：" + encryptPassword);
        System.out.println("加密后2：" + encryptPassword2);


        System.out.println("解密后1：" + decryptPassword);
        System.out.println("解密后2：" + decryptPassword2);
    }
}
